API Documentation
Public Member Functions | List of all members
nkAstraeus::lua::nkTasksWrap::LuaThread Class Referencefinal

Overrides a nkTasks::Thread to be able to use it within a Lua environment. More...

Public Member Functions

void releaseTaskRef (LuaTask *task)
 
void runScript (nkScripts::Script *script)
 

Detailed Description

Overrides a nkTasks::Thread to be able to use it within a Lua environment.

Symbols are not exported, this class is not meant to be used as is from the C++ code, but rather from the scripting environment. Documented functions are available in the environment through ThreadWrapper.

Threading in Lua has some constraints. Particularly, a given Lua state is single threaded, unless some settings at compile time for the library are enabled. For efficiency purpose, those settings are disabled when compiling the library. As such, each thread has its own environment it will work with.

This has some consequences when passing data from one thread to another; the best way to picture that is by thinking that each thread behaves as a process. This means :

However, due to the fact each thread is still a thread in C++, user data is not copied from an environment to another. Rather, the pointers are passed around. Special care needs to be taken when working with such scenario. Namely, ensure that one thread only owns the user data passed around, and make it free the data only when needed. Not doing this can lead to many threads garbage collecting the user data, causing multiple delete operations on it, leading to a crash.

To help with these operations, functions like serializeForwardOwnership() can be used.

Member Function Documentation

◆ releaseTaskRef()

void nkAstraeus::lua::nkTasksWrap::LuaThread::releaseTaskRef ( LuaTask task)

Used to release the reference over a task a thread can have, for its reference counting.

Parameters
taskThe task which reference should be released.

◆ runScript()

void nkAstraeus::lua::nkTasksWrap::LuaThread::runScript ( nkScripts::Script script)

Allows to run a script within the thread environment.

Parameters
scriptThe script to run.

The documentation for this class was generated from the following file: